#include "../comm.h"
class Solution {
public:
    int maximumPrimeDifference(vector<int>& nums) {
       vector<bool> flag(100);
       vector<int> primes;
       auto get_primes = [&](){
            for(int i = 2; i <= 100; ++i)
            {
                if(!flag[i]) primes.push_back(i);
                int u = 100 / i;
                for(int j = 0; j < primes.size() && primes[j] <= u ; ++j)
                {
                   flag[primes[j] * i] = true;
                   if(i % primes[j] == 0) break;
                }
            }
       };

       flag[1] = true;
       get_primes();
    //    for(auto e: primes) cout << e << ' ';
    // cout << flag[4] << ' ' << nums[0] << endl;
       int i = 0, j = nums.size() - 1;
       for(; i < nums.size(); ++i) if(!flag[nums[i]]) break;
       for(; j >= 0; --j) if(!flag[nums[j]]) break;
    //    cout << i << ' ' << j << endl;
       return j - i;
    }
};